<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>
        <i class="el-icon-s-home"></i>
        首页
      </el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 头部导航 -->
    <div class="tab">
      <router-link to="/home">
        <i class="el-icon-arrow-left" style="font-size: 20px; font-weight: bold; color: #000;"></i>
      </router-link>
      <p style="font-size: 14px; font-weight: bold;margin-left: 20px;">公告管理</p>
    </div>
    <div class="content">
      <div style="padding: 20px 80px;">
        <div style="display: flex;" v-for="item in data" :key="item.undefined">
          <p>现在的公告:</p>
          <p class="gg">{{ item.text }}</p>
          <button class="edit" @click="edit(item.id)">编辑</button>
        </div>

      </div>
    </div>
  </div>
</template>
<script>
import { getGaoBx, setGaoBx } from '../../utils/api'
export default {
  data() {
    return {
      data: [],
    }
  },
  created() {
    this.render()
  },
  mounted() {
    this.render()
  },
  methods: {
    render() {
      getGaoBx().then(res => {
        this.data = res.data.data
      })
    },
    edit(id) {
      this.$prompt('请输入新公告', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        setGaoBx({ id: id, text: value }).then(res => {
          if (res.status == 200) {
            this.render()
            this.$message({
              type: 'success',
              message: '修改成功'
            });
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消修改'
        });
      });
    }
  }
}
</script>
<style scoped>
.edit {
  height: 25px;
  border: 1px solid rgba(187, 187, 187, 1);
  border-radius: 3px;
  background-color: #fff;
  padding: 0 10px;
}

.gg {
  width: 150px;
  margin-left: 50px;
}

.content {
  width: 100%;
  font-size: 14px;
}

.tab {
  padding: 20px 40px;
  display: flex;
}</style>